<?php

namespace Modules\Auth\Tests\Feature;

use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Laravel\Passport\ClientRepository;
use Modules\Admin\Entities\Admin;
use Tests\TestCase;

class AuthControllerTest extends TestCase {
    use RefreshDatabase;
    // use DatabaseMigrations;
    // use DatabaseTransactions;

    public function testLogin2(){
        $response = Http::asJson()->post('127.0.0.1:8000/oauth/token', []);
        $data = $response->getBody()->getContents();
        dd($data);
        $data = json_decode($data, true);

        dd($data);
    }

    public function testLogin1() {
        $password = \Hash::make('admin111');
        // dd($password);
        Admin::factory()->state(['username' => 'admin111', 'password' => $password])->create();
        $clientRepository = new ClientRepository();
        $client = $clientRepository->createPasswordGrantClient(
            null,
            'admin',
            'http://localhost',
            'admins',
        );

        //        $this->artisan('passport:client', ['--password' =>true, '--no-interaction' => true, '--redirect_uri'=>'http://localhost', '--name'=>'test client']);
        // fetch client for id and secret
        $client = \DB::table('oauth_clients')->first();
        dump($client);
        // dd($client->getData());
        \Config::set('auth.admin.client_id', $client->id);
        \Config::set('auth.admin.client_secret', $client->secret);
        // \Config::set('auth.admin.client_id', $client->id);
        // \Config::set('auth.admin.client_secret', $client->secret);
        //////        dd(config('admin.admin_oauth_client_id'));
        \Artisan::call('passport:install');

        $this->postJson('api/admin/auth/login', [
            'username' => 'admin',
            'password' => 'asdasd',
        ])->dump();
        dd(1);
    }
}
